using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Collections;

public class RolManager
{
    public static Dictionary<string, RolBean> listahash = new Dictionary<string, RolBean>();
    public static List<RolBean> listabean = new List<RolBean>();

    public static void asignarPermiso(List<RolBean> lstRol)
    {
        listahash = new Dictionary<string, RolBean>();
        listabean = new List<RolBean>();

        foreach (RolBean rol in lstRol)
        {
            if (rol.codigopadre == null || "".Equals(rol.codigopadre))
            {
                
                rol.listaRol = lstRol.FindAll(delegate(RolBean beanrol) { return beanrol.codigopadre == rol.codigorol && beanrol.codigoperfil != null && !"".Equals(beanrol.codigoperfil); });

                if (rol.listaRol != null && rol.listaRol.Count > 0)
                {
                    listabean.Add(rol);
                }
            }

            if (rol.codigoperfil != null)
            {
                listahash.Add(rol.codigorol, rol);
            }
        }
        /////////////////////////////////

    }

    public static RolBean getUrlBean(string key)
    {
        return (listahash[key]);
    }

    public static bool tienePermisoCrear(string key)
    {
        if (listahash.ContainsKey(key))
        {
            return "T" == ((RolBean)getUrlBean(key)).crear;
        }
        return false;
    }

    public static bool tienePermisoEliminar(string key)
    {
        if (listahash.ContainsKey(key))
        {
            return "T" == ((RolBean)getUrlBean(key)).eliminar;
        }
        return false;
    }

    public static bool tienePermisoEditar(string key)
    {
        if (listahash.ContainsKey(key))
        {
            return "T" == ((RolBean)getUrlBean(key)).editar;
        }
        return false;
    }

}